package com.zx._01_基础._011_集合;

import io.netty.util.collection.IntObjectHashMap;
import java.util.HashMap;
import java.util.Map;

public class IntObjectHashMapTest {


    /**
     * HashMap, time：43
     * IntObjectHashMap, time：14  性能更好
     *
     * @param args
     */
    public static void main(String[] args) {
        test2();
        test1();
    }

    public static void test1() {
        long begin = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            Map<Integer, Integer> map = new IntObjectHashMap<>();
            for (int j = 0; j < 1000 * 1000; j++) {
                map.put(j, j);
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("IntObjectHashMap, time：" + (end - begin) / 100);
    }

    public static void test2() {
        long begin = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            Map<Integer, Integer> map = new HashMap<>();
            for (int j = 0; j < 1000 * 1000; j++) {
                map.put(j, j);
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("HashMap, time" + (end - begin) / 100);
    }
}
